//
//  YXAmendPasswordViewController.m
//  跑跑快销
//
//  Created by 杨潇 on 14-4-30.
//  Copyright (c) 2014年 ylife. All rights reserved.
//

#import "YXAmendPasswordViewController.h"

@interface YXAmendPasswordViewController ()

@end

@implementation YXAmendPasswordViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    _amendPasswordVi = [[YXAmendPasswordView alloc] init];
    self.view = _amendPasswordVi;
    
    [_amendPasswordVi.affirmBtn addTarget:self action:@selector(touchAffirmBtn) forControlEvents:UIControlEventTouchUpInside];
}

- (void)touchAffirmBtn
{
    [self.view endEditing:YES];
    UITextField * oldPWTF = (UITextField *)[_amendPasswordVi viewWithTag:1];
    UITextField * newPWTF = (UITextField *)[_amendPasswordVi viewWithTag:2];
    UITextField * affirmPWTF = (UITextField *)[_amendPasswordVi viewWithTag:3];
    if ([oldPWTF.text isEqualToString:@""]) {
        [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"请输入旧的密码。"];
        return;
    }
    if ([newPWTF.text isEqualToString:@""]) {
        [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"请输入新的密码。"];
        return;
    }
    if (![newPWTF.text isEqualToString:affirmPWTF.text]) {
        [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"两次密码输入不一致。"];
        return;
    }
    NSDictionary * infoDic = [[YXWindowInfo sharedWindowInfo] userInfoDic];
    NSLog(@"%@",[NSDictionary dictionaryWithObjectsAndKeys:@"updatePassWord",@"type",oldPWTF.text,@"oldPassWord",newPWTF.text,@"newPassWord",[[infoDic objectForKey:@"userInfo"] objectForKey:@"AccountID"],@"userId", nil]);

    [NSURLConnection sendRequestWithHeadStr:[[YXWindowInfo sharedWindowInfo] requestUrlStr] headValue:[infoDic objectForKey:@"token"] serviceToken:nil text:[NSDictionary dictionaryWithObjectsAndKeys:@"updatePassWord",@"type",oldPWTF.text,@"oldPassWord",newPWTF.text,@"newPassWord",[[infoDic objectForKey:@"userInfo"] objectForKey:@"AccountID"],@"userId", nil] dataBlock:^(NSDictionary *dic) {
        NSString * resultCode = [dic objectForKey:@"resultCode"];
        if ([resultCode isEqualToString:@"0"]) {
            [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:@"密码修改成功。"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            [[YXWindowAlertView sharedWindowAlert] showLableWithTitle:[dic objectForKey:@"errorDesc"]];
        }
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
